package com.sdy.utils;


import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
import com.sdy.po.SerialPO;

import javax.swing.*;
import java.net.URI;
import java.net.URISyntaxException;

public class MyWebSocketClient extends WebSocketClient {

    public MyWebSocketClient(String url) throws URISyntaxException {
        super(new URI(url));
    }

    @Override
    public void onOpen(ServerHandshake shake) {
        System.out.println(shake.getHttpStatusMessage());
    }

    @Override
    public void onMessage(String paramString) {
        System.out.println(paramString);
//        JSONObject jsonObject = null;
//        try {
//            jsonObject = JSON.parseObject(paramString);
//            if ((Boolean)jsonObject.get("result")){
//                SerialFactory.serialList = JSON.parseArray(jsonObject.get("data").toString(),SerialPO.class);
//            }
//            else if (!(Boolean)jsonObject.get("result")){
//                System.out.println("识别码不正确");
//                JOptionPane.showMessageDialog(null, "识别码不正确...... ");
//            }
//        }catch (Exception e){
//
//        }
    }

    @Override
    public void onClose(int paramInt, String paramString, boolean paramBoolean) {
        System.out.println("关闭");
    }

    @Override
    public void onError(Exception e) {
        System.out.println("发生错误");
    }
}
